<?php

namespace App\Models;

use App\Common\Constant\Params;
use App\Services\IStorageService;
use Illuminate\Database\Eloquent\Model;

class Banner extends BaseModel
{
    protected $table = 'banner';

    const CREATED_AT = 'add_time';
    const UPDATED_AT = 'upd_time';

    protected $dateFormat = 'U';

    protected $fillable = [
        'name',
        'banner_img',
        'sort',
        'url'
    ];

    protected $casts = [
        'sort'=>'integer'
    ];

    /**
     * 获取banner url绝对地址
     * banner_img_url
     */
    public function getBannerImgUrlAttribute()
    {
        if (empty($this->banner_img)){
            return '';
        }else{
            return resolve(IStorageService::class)->getUrl($this->banner_img);
        }
    }
}
